<template>
	<view>
		<view class="download" v-if="type==1">
			<p class="entry-hd">立即下载APP</p>
			<view class="xz">
				<view class="xzview" style="margin:0 auto;width:130px;height:45px;">
					<view id="JdownApp" @click="openBrowser()">
						<span id="left" style="width:100%;height:100%;background:#337ecc;border-radius:10px;color:white;line-height:45px;text-align:center;float:left;font-size:13px;">
							医院/医生下载
						</span>
					</view>
				</view>
			</view>
		</view>
		<view class="download" v-if="type==2">
			<p class="entry-hd">立即下载APP</p>
			<view class="xz">
				<view class="xzview" style="margin:0 auto;width:130px;height:45px;">
					<view id="JdownApp" @click="openBrowser()">
						<span id="left" style="width:100%;height:100%;background:#337ecc;border-radius:10px;color:white;line-height:45px;text-align:center;float:left;font-size:13px;">
							携联助手下载
						</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apklocation:'',	// apk地址
				isShow:false,	// 是否点击下载
				type:1,			// 下载APP（1：医院/医生APP  2：携联助手APP）
			}
		},
		onLoad(opt) {
			this.type = opt.type;
			if(opt.type==1){
				//得医院/医生APP下载地址
				uni.request({
					url:'http://xljksc.com/api/upgrade',
					success: (res) => {
						if(res.data.code==200){
							this.apklocation = res.data.data.url;
						}
					}
				})
			}else if(opt.type==2){
				//得客服APP下载地址
				uni.request({
					url:'/zitiapk/zhushoudownload',
					data:{
						userid:uni.getStorageSync('usersId')
					},
					success: (res) => {
						if(res.data.code==200){
							this.apklocation = this.host+res.data.data.fileaddress;
						}else{
							this.$u.toast("需要购买携联品牌商品才能下载此APP")
						}
					}
				})
			}
		},
		methods: {
			//点击到浏览器下载
			openBrowser(){
				console.log(this.apklocation)
				if(this.isNull(this.apklocation)){
					this.$u.toast("下载失败")
					return
				}else{
					uni.showModal({
						title:"请复制下方链接到浏览器下载",
						content:this.apklocation,
						success: (res) => {
							if(res.confirm){
								uni.setClipboardData({
									data: this.apklocation,
									success: function(){
										// uni.showToast({
										//   title: `复制成功`,
										//   icon: 'none'
										// })
									}
								})
							}
						}
					})
				}
			},
			//判空
			isNull(str){
				return str==null || str=="" || str==undefined
			}
		}
	}
</script>

<style>
	page{
		background-color: green;
	}
	*{
		margin:0px;
		padding:0px;
	}
	body,html{
		width:100%;height:100%;background:green;
	}
	.wxtip{background: rgba(0,0,0,0.8); text-align: center; position: fixed; left:0; top: 0; width: 100%; height: 100%; z-index: 998; display: none;}
	.wxtip-icon{width: 52px; height: 67px; display: block; position: absolute; right: 20px; top: 20px;}
	.wxtip-txt{margin-top: 107px; color: #fff; font-size: 20px; line-height: 1.5;}
	.welcome-bg {
		background-size:100%  100%;
		position: relative;
		font-family: "微软雅黑";
		text-align: center;
	}
	.welcome-bg img {
		width: 40%;
		display: block;
		position: absolute;
		top: 90px;
		left: 30%;
		border-radius:100%;
	}
	
	.welcome-bg h1 {
		position: absolute;
		width: 60%;
		top: 250px;
		left: 20%;
		color: orangered;
		
	}
	.welcome-bg h5 {
		position: absolute;
		top: 295px;
		width: 60%;
		left: 20%;
	}
	.download{
		position: absolute;
		top: 200px;
		background: white;
		width: 100%;
		height: 300px;
	}
	.download a img{
		float: left;
		width: 130px;
		height: 44px;
	}
	.entry-hd{
		margin: 30px;
		text-align: center;
		font-size: 2em;
	}
	.xz{
		width: 100%;
		height: 50px;
		float: left;
	}
	.xz .xzview{
		width:82%;
		height: 100%;
		margin: 0px auto;
	}
	#left{
		float: left;
	}
</style>
